local root = require 'script.mpq.w2l.w2l_path'

local function ydwe_ui(w2l)
    local ydwe_path = require 'script.mpq.w2l.ydwe_path'
    local ydwe = ydwe_path()
    if not ydwe then
        return nil, '未找到ydwe'
    end
    if fs.exists(ydwe / 'ui') then
        return ydwe / 'ui'
    elseif fs.exists(ydwe / 'share' / 'ui') then
        return ydwe / 'share' / 'ui'
    elseif fs.exists(ydwe / 'share' / 'mpq') then
        return ydwe / 'share' / 'mpq'
    else
        return nil, '未找到触发数据'
    end
end

return function (w2l, filename)
    if filename:sub(1, 3) == 'ui\\' and w2l.setting.data_ui == '${YDWE}' then
        if not w2l.ydwe_ui then
            w2l.ydwe_ui = { ydwe_ui() }
        end
        if not w2l.ydwe_ui[1] then
            return nil, w2l.ydwe_ui[2]
        end
        return io.load(w2l.ydwe_ui[1] / filename:sub(4))
    end
    -- print('data_load:', w2l.setting.data, filename, root / 'script\\mpq\\w2l\\data' / w2l.setting.data / filename)

    return io.load(root / 'script\\mpq\\w2l\\data' / w2l.setting.data / filename)
end
